package com.mjw.zstu.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mjw.zstu.entity.User;
import com.mjw.zstu.entity.Visitor;
import com.mjw.zstu.mapper.UserMapper;
import com.mjw.zstu.mapper.VisitorMapper;
import com.mjw.zstu.resultDto.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import static com.mjw.zstu.untils.Zxing.zxing;

@Service
public class VisitorService {
    @Autowired
    VisitorMapper visitorMapper;
    @Autowired
    UserMapper userMapper;
    public JsonResult getUserList(int user_id){
        List l= visitorMapper.getlist(user_id);
        return new JsonResult(200,"获取成功",l);
    }
    public JsonResult add(int user_id,int exhibition_id){
//        User user=userMapper.selectById(user_id);
//        if(user.getStatus()==1){
//            return new JsonResult(200,"账号已被拉黑不可参加会展",null);
//        }
        Visitor visitor=new Visitor();
        visitor.setExhibition_id(exhibition_id);
        visitor.setUser_id(user_id);
        QueryWrapper<Visitor> visitorQueryWrapper=new QueryWrapper<>(visitor);
        int i=visitorMapper.selectCount(visitorQueryWrapper);
        if(i>0){
            return new JsonResult(500,"不可重复参加",null);
        }
        String str=zxing(exhibition_id,user_id);
        visitor.setZxing(str);

        visitorMapper.insert(visitor);
        return new JsonResult(200,"获取成功",null);
    }
    public JsonResult delete(int visitor_id){
        visitorMapper.deleteById(visitor_id);
        return new JsonResult(200,"退出成功",null);
    }
    public JsonResult detail(int visitor_id){
       Map m= visitorMapper.detail(visitor_id);
       return new JsonResult(200,"获取成功",m);
    }
}
